import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:umeng_push_demo/view/home_page.dart';
import 'package:umeng_push_demo/view/setting_page.dart';

/// FileName routes
///
/// @Author 陈晓星
/// @Date 2024/10/25 08:49
///
/// @Description TODO

enum AppRoutes {
  /// 配置列表
  configList(path: "/", page: HomePage()),
  setting(path: "/setting", page: SettingPage()),
  ;

  final String path;
  final Widget page;
  const AppRoutes({required this.path, required this.page});

  GetPage get getPage {
    return GetPage(name: path, page: () => page, transition: Transition.rightToLeft);
  }

  static List<GetPage> get allGetPages {
    return AppRoutes.values.map((e) => e.getPage).toList();
  }

  /// 用于路由监听
  static final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();

  /// 页面跳转
  static Future<T?>? to<T>(AppRoutes routes, {dynamic arguments}) {
    return Get.toNamed<T?>(routes.path, arguments: arguments);
  }

  /// 页面返回
  static void back<T>({
    T? result,
    bool closeOverlays = false,
    bool canPop = true,
    int? id,
  }) {
    Get.back(
        result: result,
        closeOverlays: closeOverlays,
        canPop: canPop,
        id: id
    );
  }

  /// 直到页面返回
  static void until(RoutePredicate predicate, {int? id}) {
    Get.until(predicate, id: id);
  }

  /// 关闭当前页并跳转到新的页面
  static Future<T?>? off<T>(AppRoutes routes, {dynamic arguments}) {
    return Get.off(routes.page, arguments: arguments);
  }
}